<?php

class Wilayah_model extends CI_Model {
	
	public function get_wilayah_all($limit = 20, $offset = 0, $search = '')
	{
		$this->db->order_by('child_id', 'ASC');
		$this->db->limit($limit, $offset);
		$query = $this->db->get('t_mtr_lokasi');
		
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}
	
	public function get_total_rows()
	{
		return $this->db->count_all('t_mtr_lokasi');
	}
	
	public function get_propinsi()
	{
		$this->db->where('status', 1);
		$this->db->order_by('propinsi_id', 'ASC');
		$query = $this->db->get('t_mtr_propinsi');
		
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}
			
	public function get_kabupaten()
	{
		$this->db->where('status', 1);
		$this->db->order_by('kabupaten_id', 'ASC');
		$query = $this->db->get('t_mtr_kabupaten');
		
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}
		
	public function get_rows_kabupaten($parent_id = 7)
	{
		$this->db->where('jenis', 'KB');
		$this->db->where('parent_id', $parent_id);
		$this->db->from('t_mtr_lokasi');	
		return $this->db->count_all_results();
	}
	
	
	public function get_kecamatan()
	{
		$this->db->where('jenis', 'KC');
		$this->db->order_by('child_id', 'ASC');
		$query = $this->db->get('t_mtr_lokasi');
		
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}
		
	public function get_rows_kecamatan($parent_id = 7)
	{
		$this->db->where('jenis', 'KC');
		$this->db->where('parent_id', $parent_id);
		$this->db->from('t_mtr_lokasi');	
		return $this->db->count_all_results();
	}
	
	
	
}